package com.ruoyi.zyx.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxOrdershare;
import com.ruoyi.zyx.service.IZyxOrdershareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 共享Controller
 *
 * @author lhs
 * @date 2021-06-10
 */
@RestController
@RequestMapping("/zyx/ordershare")
public class ZyxOrdershareController extends BaseController
{
    @Autowired
    private IZyxOrdershareService zyxOrdershareService;

    /**
     * 查询共享列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:ordershare:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZyxOrdershare zyxOrdershare)
    {
        startPage();
        List<ZyxOrdershare> list = zyxOrdershareService.selectZyxOrdershareList(zyxOrdershare);
        return getDataTable(list);
    }

    @GetMapping("/listMyOrdershare")
    public TableDataInfo listMyOrdershare(ZyxOrdershare zyxOrdershare)
    {
        zyxOrdershare.setUserid(SecurityUtils.getLoginUser().getUser().getUserId());
        startPage();
        List<ZyxOrdershare> list = zyxOrdershareService.listMyOrdershare(zyxOrdershare);
        return getDataTable(list);
    }

    /**
     * 导出共享列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:ordershare:export')")
    @Log(title = "共享", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxOrdershare zyxOrdershare)
    {
        List<ZyxOrdershare> list = zyxOrdershareService.selectZyxOrdershareList(zyxOrdershare);
        ExcelUtil<ZyxOrdershare> util = new ExcelUtil<ZyxOrdershare>(ZyxOrdershare.class);
        return util.exportExcel(list, "共享数据");
    }

    /**
     * 获取共享详细信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:ordershare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zyxOrdershareService.selectZyxOrdershareById(id));
    }

    /**
     * 新增共享
     */
    @PreAuthorize("@ss.hasPermi('zyx:ordershare:add')")
    @Log(title = "共享", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxOrdershare zyxOrdershare)
    {
        return toAjax(zyxOrdershareService.insertZyxOrdershare(zyxOrdershare));
    }

    /**
     * 修改共享
     */
    @PreAuthorize("@ss.hasPermi('zyx:ordershare:edit')")
    @Log(title = "共享", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxOrdershare zyxOrdershare)
    {
        return toAjax(zyxOrdershareService.updateZyxOrdershare(zyxOrdershare));
    }

    /**
     * 删除共享
     */
    @PreAuthorize("@ss.hasPermi('zyx:ordershare:remove')")
    @Log(title = "共享", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zyxOrdershareService.deleteZyxOrdershareByIds(ids));
    }
}
